<?php

namespace app\common\command;
use addons\shopro\service\Wallet as WalletService;
use app\admin\model\market\Acceleration;
use app\admin\model\shopro\commission\Agent;
use app\admin\model\shopro\user\WalletLog;
use app\admin\model\user\Agency;
use app\common\model\shopro\ReleaseAccelerateLogModel;
use app\common\model\shopro\ReleaseAccelerateMarketplaceLogModel;
use app\common\model\shopro\UserTeamDayWalletLogModel;
use app\common\model\User;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\exception\HttpResponseException;

class Pingjirelease extends Command
{
    protected function configure()
    {
        $this->setName('pingjireleasev')->setHelp('平级奖励')->setDescription('平级奖励');

    }

    protected function execute(Input $input, Output $output)
    {
//        $data        = $dayLogModel->whereTime('endtime','d')->select();
        $model = new Agency();
        $data        = $model->where('status','=',0)->select();
            if ($data) {
                Db::startTrans();
                try {
                    foreach ($data as $k=>$v){
                        $v->status = 1;
                        $v->save();
                        if($v->type == 1){
                            $event = 'jicha_team_choujiang';
                            $memo  = '砸金蛋级差奖励';
                        }else{
                            $event = 'pingji_team_choujiang';
                            $memo  = '砸金蛋平级奖励';
                        }
                        WalletService::change($v->user_id, 'score', $v->commission, $event,[],
                            $memo);
                    }
                    Db::commit();
                    echo '执行成功';
                } catch (HttpResponseException $e) {
                    Db::rollback();
                    $data    = $e->getResponse()->getData();
                    $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
                    echo $message;
//                    format_log_error($e, 'Release.pingji-jicha.HttpResponseException', $message);
                }
            } else {
                echo "无数据";
            }
    }
}
